﻿using GalaSoft.MvvmLight;
using System.Windows;
using System.Windows.Media;
using TransControlSystem.Enum;

namespace TransControlSystem.Model
{
    public class TagInfo : ObservableObject
    {
        #region 数据库TagInfo表中的字段
        /// <summary>
        /// 主键
        /// </summary>
        private int _Id;
        /// <summary>
        /// 主键
        /// </summary>
        public int Id
        {
            get { return _Id; }
            set
            {
                _Id = value;
                RaisePropertyChanged(() => Id);
            }
        }

        /// <summary>
        /// 设备名称
        /// </summary>
        private string _EquipmentName;
        /// <summary>
        /// 设备名称
        /// </summary>
        public string EquipmentName
        {
            get { return _EquipmentName; }
            set
            {
                _EquipmentName = value;
                RaisePropertyChanged(() => EquipmentName);
            }
        }
        /// <summary>
        /// 排序序号
        /// </summary>
        private int _OrderNo;
        /// <summary>
        /// 排序序号
        /// </summary>
        public int OrderNo
        {
            get { return _OrderNo; }
            set
            {
                _OrderNo = value;
                RaisePropertyChanged(() => OrderNo);
            }
        }

        /// <summary>
        /// 程序块名称
        /// </summary>
        private string _TagDesc;
        /// <summary>
        /// 程序块名称
        /// </summary>
        public string TagDesc
        {
            get { return _TagDesc; }
            set
            {
                _TagDesc = value;
                RaisePropertyChanged(() => TagDesc);
            }
        }
        /// <summary>
        /// 程序块地址
        /// </summary>
        private string _Address;
        /// <summary>
        /// 程序块地址
        /// </summary>
        public string Address
        {
            get { return _Address; }
            set
            {
                _Address = value;
                RaisePropertyChanged(() => Address);
            }
        }
        /// <summary>
        /// 程序块值数据类型
        /// </summary>
        private string _ValueType;
        /// <summary>
        /// 程序块值数据类型
        /// </summary>
        public string ValueType
        {
            get { return _ValueType; }
            set
            {
                _ValueType = value;
                RaisePropertyChanged(() => ValueType);
            }
        }
        /// <summary>
        /// 程序块值
        /// </summary>
        private string _Value;
        /// <summary>
        /// 程序块值
        /// </summary>
        public string Value
        {
            get { return _Value; }
            set
            {
                _Value = value;
                RaisePropertyChanged(() => Value);
            }
        }
        /// <summary>
        /// 读写属性：True=只读，False=可读可写
        /// </summary>
        private bool _ReadOrWrite;
        /// <summary>
        /// 读写属性：True=只读，False=可读可写
        /// </summary>
        public bool ReadOrWrite
        {
            get { return _ReadOrWrite; }
            set
            {
                _ReadOrWrite = value;
                RaisePropertyChanged(() => ReadOrWrite);
            }
        }
        /// <summary>
        /// 程序块的说明
        /// </summary>
        private string _Remark;
        /// <summary>
        /// 程序块的说明
        /// </summary>
        public string Remark
        {
            get
            {
                return _Remark;
            }
            set
            {
                _Remark = value;
                RaisePropertyChanged(() => Remark);
            }
        }
        /// <summary>
        /// 是否可用：true是启用，false是不启用
        /// </summary>
        private bool _IsEnable;
        /// <summary>
        /// 是否可用：true是启用，false是不启用
        /// </summary>
        public bool IsEnable
        {
            get { return _IsEnable; }
            set
            {
                _IsEnable = value;
                RaisePropertyChanged(() => IsEnable);
            }
        }
        /// <summary>
        /// 类别：1是普通程序块，2是任务程序块，3是加料车任务反馈程序块
        /// </summary>
        private int _Type;
        /// <summary>
        /// 类别：1是普通程序块，2是任务程序块，3是加料车任务反馈程序块
        /// </summary>
        public int Type
        {
            get { return _Type; }
            set
            {
                _Type = value;
                RaisePropertyChanged(() => Type);
            }
        }
        /// <summary>
        /// 点位
        /// </summary>
        private string _Point;
        /// <summary>
        /// 点位
        /// </summary>
        public string Point
        {
            get
            {
                return _Point;
            }
            set
            {
                _Point = value;
                RaisePropertyChanged(() => Point);
            }
        }
        #endregion 数据库TagInfo表中的字段

        /// <summary>
        /// 主界面MainModel用来判断执行完成的标签名的值对应的是哪个任务
        /// </summary>
        public string TagDesc2
        {
            get
            {
                string TaskContent = null;
                if (TagDesc == "执行完成的标签名")
                {
                    switch (int.Parse(Value))
                    {
                        case 1:
                            TaskContent = "将1#冷却室的铝料移至1#解垛位";
                            break;
                        case 2:
                            TaskContent = "将1#冷却室的铝料移至2#解垛位";
                            break;
                        case 3:
                            TaskContent = "将1#冷却室的铝料移至3#解垛位";
                            break;
                        case 4:
                            TaskContent = "将2#冷却室的铝料移至1#解垛位";
                            break;
                        case 5:
                            TaskContent = "将2#冷却室的铝料移至2#解垛位";
                            break;
                        case 6:
                            TaskContent = "将2#冷却室的铝料移至3#解垛位";
                            break;
                        case 7:
                            TaskContent = "将1#均质炉的铝料移至1#冷却室";
                            break;
                        case 8:
                            TaskContent = "将1#均质炉的铝料移至2#冷却室";
                            break;
                        case 9:
                            TaskContent = "将2#均质炉的铝料移至1#冷却室";
                            break;
                        case 10:
                            TaskContent = "将2#均质炉的铝料移至2#冷却室";
                            break;
                        case 11:
                            TaskContent = "将3#均质炉的铝料移至1#冷却室";
                            break;
                        case 12:
                            TaskContent = "将3#均质炉的铝料移至2#冷却室";
                            break;
                        case 13:
                            TaskContent = "将4#均质炉的铝料移至1#冷却室";
                            break;
                        case 14:
                            TaskContent = "将4#均质炉的铝料移至2#冷却室";
                            break;
                        case 15:
                            TaskContent = "将1#堆垛位的铝料移至1#均质炉";
                            break;
                        case 16:
                            TaskContent = "将1#堆垛位的铝料移至2#均质炉";
                            break;
                        case 17:
                            TaskContent = "将1#堆垛位的铝料移至3#均质炉";
                            break;
                        case 18:
                            TaskContent = "将1#堆垛位的铝料移至4#均质炉";
                            break;
                        case 19:
                            TaskContent = "将2#堆垛位的铝料移至1#均质炉";
                            break;
                        case 20:
                            TaskContent = "将2#堆垛位的铝料移至2#均质炉";
                            break;
                        case 21:
                            TaskContent = "将2#堆垛位的铝料移至3#均质炉";
                            break;
                        case 22:
                            TaskContent = "将2#堆垛位的铝料移至4#均质炉";
                            break;
                        case 23:
                            TaskContent = "将1#隔条仓的空隔条架子移至隔条总仓";
                            break;
                        case 24:
                            TaskContent = "将3#隔条仓的隔条移至1#隔条仓";
                            break;
                        case 25:
                            TaskContent = "将隔条总仓的空隔条架子移至3#隔条仓";
                            break;
                        case 26:
                            TaskContent = "将2#隔条仓的空隔条架子移至隔条总仓";
                            break;
                        case 27:
                            TaskContent = "将3#隔条仓的隔条移至2#隔条仓";
                            break;
                        case 28:
                            TaskContent = "搬运1#解垛位底部隔条";
                            break;
                        case 29:
                            TaskContent = "搬运2#解垛位底部隔条";
                            break;
                        case 30:
                            TaskContent = "搬运3#解垛位底部隔条";
                            break;
                        case -1:
                            TaskContent = "错误";
                            break;
                    }
                    return _TagDesc + ":" + TaskContent;
                }
                else
                {
                    return _TagDesc + ":" + Value;
                }

            }
        }
        private bool _SomeConditionalProperty;
        public bool SomeConditionalProperty
        {
            get
            {

                return _SomeConditionalProperty;
            }
            set
            {
                _SomeConditionalProperty = value;
                RaisePropertyChanged(() => SomeConditionalProperty);
            }
        }
        public Brush Background => SomeConditionalProperty ? Brushes.Red : Brushes.White;
        /// <summary>
        /// 程序款地址配置和通讯测试显示使用
        /// </summary>
        private string _ReadOrWriteText;
        /// <summary>
        /// 程序款地址配置和通讯测试显示使用
        /// </summary>
        public string ReadOrWriteText
        {
            get
            {
                if (ReadOrWrite)
                {
                    _ReadOrWriteText = "可读";
                }
                else
                {
                    _ReadOrWriteText = "可读可写";
                }
                return _ReadOrWriteText;
            }
            set
            {
                _ReadOrWriteText = value;
                RaisePropertyChanged(() => ReadOrWriteText);
            }
        }
        /// <summary>
        /// 程序款地址配置和通讯测试显示使用
        /// </summary>
        private string _IsEnableText;
        /// <summary>
        /// 程序款地址配置和通讯测试显示使用
        /// </summary>
        public string IsEnableText
        {
            get
            {
                if (_IsEnableText == null)
                {
                    if (IsEnable)
                    {
                        _IsEnableText = "已启用";
                    }
                    else
                    {
                        _IsEnableText = "已禁用";
                    }
                }

                return _IsEnableText;
            }
            set
            {
                _IsEnableText = value;
                RaisePropertyChanged(() => IsEnableText);
            }
        }
        /// <summary>
        /// 程序块颜色 用来显示主界面设备颜色
        /// </summary>
        private LinearGradientBrush _TagColor;
        /// <summary>
        /// 程序块颜色 用来显示主界面设备颜色
        /// </summary>
        public LinearGradientBrush TagColor
        {
            get
            {
                if (ValueType == "Bool" && Value == "True")
                {
                    _TagColor = StatusColor.NoAlgorithmFull();
                }
                else if (TagDesc == "执行完成的标签名" && ValueType == "DInt" && Value != "0")
                {
                    _TagColor = StatusColor.NoAlgorithmEmpty();
                }
                else if (TagDesc == "执行完成的标签名" && ValueType == "DInt" && Value == "0")
                {
                    _TagColor = StatusColor.NoAlgorithmEmpty();
                }
                else if (ValueType == "DInt" && Value == "0")
                {
                    _TagColor = StatusColor.NoAlgorithmFull();
                }
                return _TagColor;
            }
            set
            {
                _TagColor = value;
                RaisePropertyChanged(() => TagColor);
            }
        }
        /// <summary>
        /// 通讯测试显示修改按钮使用
        /// </summary>
        public Visibility ComTestWriteVisibility
        {
            get
            {
                if (ReadOrWrite)
                {
                    return Visibility.Hidden;
                }
                else
                {
                    return Visibility.Visible;
                }
            }
        }
    }
}
